package com.qef.com.mmovie.activity;

import android.graphics.Color;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.SaveCallback;
import com.qef.com.mmovie.App;
import com.qef.com.mmovie.R;
import com.qef.com.mmovie.base.SimpleActivity;
import com.qef.com.mmovie.entity.User;
import com.qef.com.mmovie.utils.HindToolbar;
import com.qef.com.mmovie.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 2016 逛街购（北京）网络科技有限公司，版权所有
 * guangjiegou - Android客户端
 * Context:意见反馈
 * Created by fanenqian on 2017/5/17 17:47
 */

public class FeedbackActivity extends SimpleActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.feed_back_btn)
    Button btFeed;
    @BindView(R.id.feed_back_tv)
    EditText etFeed;

    @Override
    protected int getLayout() {
        HindToolbar.setHintWindowTitle(getWindow());
        return R.layout.layout_feedback;
    }

    @Override
    protected void initEventAndData() {
        initView();
    }

    private void initView() {
        ButterKnife.bind(this);
        toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
        toolbar.setNavigationOnClickListener(v -> onBackPressed());
        toolbar.setTitle("意见反馈");
        toolbar.setTitleTextColor(Color.WHITE);
    }

    @OnClick(R.id.feed_back_btn)
    public void onClick(View v) {
        if (etFeed.getText().toString().length() == 0) {
            ToastUtil.showToast(App.getInstance(), "消息内容不能为空");
        }
        addInfo();
    }

    private void addInfo() {
        AVObject feed = new AVObject("FeedBack");
        feed.put("info", etFeed.getText().toString());
        feed.put("userInfo", User.getCurrenUser().getUsername());
        feed.saveInBackground(new SaveCallback() {
            @Override
            public void done(AVException e) {
                ToastUtil.showToast(App.getInstance(), "提交成功！感谢您的反馈");
                finish();
            }
        });
    }
}
